import cv2
import numpy as np
import cv2 as cv
import xlwings as xw
from PIL import Image
img = cv2.imread("6.jpeg",cv2.IMREAD_GRAYSCALE)
# cv2.imshow("thds",img)
print(img.shape)

t1 , thd = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
# athdMEAN = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,5,3)
# athdGAus = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,5,3)
print(img.shape)
cv2.imshow("thd",thd)
width=img.shape[0]
height=img.shape[1]
Value = [[0] * height for i in range(width)]  # 创建一个大小与图片相同的二维数组
# print(thd)
app=xw.App(visible=True,add_book=True)
wb=app.books.add()
sht =wb.sheets.active
for i in range(width):
    for j in range(height):
        if thd[i,j]>0:
            sht.range(i, j).color = 255, 200, 255
            # Value[i][j]=1

cv2.imshow("thd",thd)

# sht.range(1,1).value="b1"

wb.save('1.xlsx')
# wb.close()
# #结束进程
# app.quit()
# print(thd)
print(Value)
print(img.shape)


cv2.waitKey()
cv2.destroyAllWindows()